function[idx_best, dealer_best, Weffi]=allocative_efficient(input_file)

global T kappa  
    
    load(input_file);
    theta=Y(new_period(:,2),6);
    
    muI  = NaN*ones(T,1);
    muR  = NaN*ones(T,1);
    
    for t=1:T
        idx = (new_period(t,2):new_period(t,3))';
        
        if side==1
            idxI = idx(find(Y(idx,1)==1, 1, 'first'));
            idxR = idx(find(Y(idx,1)==2, 1, 'first'));
            
        elseif side==-1
            idxI = idx(find(Y(idx,1)==3, 1, 'first'));
            idxR = idx(find(Y(idx,1)==4, 1, 'first'));  
        end 
        
        if ~isempty(idxR)
        muR(t) = Y(idxR,24);
        end 
        if ~isempty(idxI)
        muI(t) = Y(idxI,24);
        end 
    end 

    if side==1      
        vdjSQ      = vdjSQ_IB;
        nettradeSP = vdjSQ+ xij_data;
        Gt         = vdjSQ+ xij_data - theta -kappa*muR - (1-kappa)*muI;
    elseif side==-1 
        vdjSQ      = vdjSQ_IS;
        nettradeSP = xij_data-vdjSQ;
        Gt         = theta +kappa*muR + (1-kappa)*muI + xij_data-vdjSQ;
    end 
    
    best_nettradeSP = nanmax(nettradeSP')';
    best_xij        = nanmax(xij_data')';
    best_vQ         = nanmax(vdjSQ')';
    idx_best        = NaN*ones(size(nettradeSP,1),1);
    idx_best_xij    = NaN*ones(size(nettradeSP,1),1);
    idx_best_vQ     = NaN*ones(size(nettradeSP,1),1);
    dealer_best     = NaN*ones(size(nettradeSP,1),1);
    Weffi           = NaN*ones(size(nettradeSP,1),1);
    
    for i=1:size(nettradeSP,1)
        if ~isnan(best_nettradeSP(i,:))
        idx_best(i)     = find(nettradeSP(i,:)==best_nettradeSP(i,:));
        idx_best_xij(i) = find(xij_data(i,:)==best_xij(i,:), 1, 'first'); 
        idx_best_vQ(i)  = find(vdjSQ(i,:)==best_vQ(i,:), 1, 'first'); 
        dealer_best(i)  = dealer_idsSQ(i,idx_best(i));
        Weffi(i)        = Imax * Gt(i,idx_best(i));
        end
    end 
    
    disp(['Number of days where the best dealer is the one with highest quality: ', num2str(sum(idx_best_xij==idx_best_vQ)), ' out of ', num2str(size(nettradeSP,1))])
    
 
    